<?php
	$connection = mysqli_connect("localhost","root","","frederik-adressedatabase");
	$query = "SELECT * FROM postnummer ORDER BY postnummer";
	$result = mysqli_query($connection,$query);
?>
<a href="navneliste.php">Tilbage til navne-liste</a>
<form action="nyperson.php">
    <table border="1">
        <tr>
            <th>Fornavn</th><td><input type="text" name="fornavn" required /></td>
       	</tr>
        <tr>
            <th>Efternavn</th><td><input type="text" name="efternavn" required /></td>
       	</tr>
        <tr>
            <th>Postnr.</th>
            <td>
            	<select name="postnummer">
                	<?php
						while($record = mysqli_fetch_array($result)){
							echo "<option value='$record[Postnummer]'>$record[Postnummer]</option>";
						}
					?>
                </select>
			</td>
      	</tr>
        <tr>
        	<th>Gade</th><td><input type="text" name="gade" /></td>
        </tr>
        <tr>
        	<td><input type="submit" value="Opret" /></td>
        </tr>
	</table>
</form>
<?php
	if(isset($_REQUEST["fornavn"])&&($_REQUEST["efternavn"])){
		$query = "INSERT INTO person(Fornavn,Efternavn,Postnummer,Gade) VALUES('$_REQUEST[fornavn]','$_REQUEST[efternavn]',$_REQUEST[postnummer],'$_REQUEST[gade]')";
		echo $query;
		$result = mysqli_query($connection,$query);
	}
?>